<template>
	<view class="myAuth">
		<view class="topTitle">
			<titleItem title1st="欢迎加入团洗平台 ，请填写申请信息" subTitle="">
			</titleItem>
		</view>
		<u--form labelPosition="left" :model="formData" :rules="rules" ref="form1">
			<u-form-item label="分销商名称" prop="mobile" borderBottom ref="item1" labelWidth="120" :required="type!=1">
				<u--input v-model="formData.mobile" border="none" placeholder="请输入分销商名称" maxlength="11" type="number">
				</u--input>
			</u-form-item>
			<u-form-item label="手机号码(账号)" prop="mobile" borderBottom ref="item1" labelWidth="120" :required="type!=1">
				<u--input v-model="formData.mobile" border="none" placeholder="请输入分销商名称" maxlength="11" type="number">
				</u--input>
			</u-form-item>
			<u-form-item label="密码" prop="mobile" borderBottom ref="item1" labelWidth="120" :required="type!=1">
				<u--input v-model="formData.mobile" border="none" placeholder="请输入渠道名称" maxlength="11" type="number">
				</u--input>
			</u-form-item>
			<u-form-item label="对账邮箱" prop="mobile" borderBottom ref="item1" labelWidth="120" :required="type!=1">
				<u--input v-model="formData.mobile" border="none" placeholder="请输入渠道名称" maxlength="11" type="number">
				</u--input>
			</u-form-item>
			<u-form-item label="手机号码" prop="mobile" borderBottom ref="item1" labelWidth="120" :required="type!=1">
				<u--input v-model="formData.mobile" border="none" placeholder="请输入渠道名称" maxlength="11" type="number">
				</u--input>
			</u-form-item>
			<u-form-item label="收款账号" prop="mobile" borderBottom ref="item1" labelWidth="100" :required="type!=1">
				<u--input v-model="formData.mobile" border="none" placeholder="请输入渠道名称" maxlength="11" type="number">
				</u--input>
			</u-form-item>
		</u--form>
		<view class="botBtn">
			<view style="width: 100%;">
				<u-button class="custom-style" text="提交"
					customStyle="border-radius: 50px;background: var(--unnamed, linear-gradient(90deg, #218CC9 0%, #2CB9A4 100%));;color:#fff;margin-top:20px;border-radius: 30px;" @click="goAuth">
				</u-button>
			</view>
		</view>

	</view>
</template>
<style>
	page {
		background-color: #fff;
	}
</style>
<script>
	import eventBUs from '../../utils/eventBus.js'
	import vvSelect from '@/components/vv-select/vv-select.vue'
	import titleItem from '@/components/common/titleItem.vue'
	import {
		getIbec,
		profile,
		getStaff
	} from '@/request/api.js'
	export default {
		components: {
			vvSelect,
			titleItem
		},
		data() {
			return {
				actions: [],
				showSex: false,
				formData: {
					mobile: "",
					ibec_id: '',
					name: ''
				},
				ibecName: '',
				rules: {
					'mobile': {
						required: true,
						message: '请输入正确的手机号码',
						trigger: ['change', 'blur'],
						max: 11,
						validator: (rule, value, callback) => {
							// 上面有说，返回true表示校验通过，返回false表示不通过
							// this.$u.test.mobile()就是返回true或者false的
							return this.$u.test.mobile(value);
						},
					},
					'ibec_id': {
						type: 'string',
						transform(value) {
							return String(value);
						},
						required: true,
						message: '请选择经济公司',
						trigger: ['blur', 'change']
					},
				}
			}
		},
		onLoad() {
			// this.getUser()
			// this.getIbec()
		},
		methods: {
			pickerChange(e, name) {
				// console.log(e,name)
				this.formData.ibec_id = e.toString()
				this.$refs.form1.validateField('ibec_id')
			},
			async getUser() {
				let res = await getStaff()
				this.formData.name = res.data.ibec.name
				this.formData.ibec_id = res.data.ibec.id
				this.formData.mobile = res.data.mobile
				uni.setStorageSync('userInfo', res.data)
				this.$eventBus.$emit('hasLogin', true);
			},
			async getIbec() {
				let res = await getIbec()
				this.actions = res.data
				console.log(this.actions)
			},
			select(e) {
				this.formData.name = e.name
				this.formData.ibec_id = e.id
				this.$refs.form1.validateField('ibec_id')
			},
			goAuth() {
				this.$refs.form1.validate().then(res => {
					delete this.formData.name
					profile(this.formData).then(res => {
						if (res.code == 200) {
							uni.navigateTo({
								url: '/my_pages/components/success?title=修改个人信息成功'
							})
							this.getUser()
						}
					})
				}).catch(errors => {
					uni.$u.toast('请正确填写信息')
				})
			}
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.form1.setRules(this.rules)
		},
	}
</script>

<style lang="scss" scoped>
	.myAuth {
		padding: 30rpx;

		.topTitle {
			margin-left: -20px;
			margin-right: 20px;
		}

	}

	::v-deep .u-input {
		background-color: #fff !important;
	}

	::v-deep .u-transition {
		overflow: scroll !important;
		height: 50vh !important;
	}

	.compony {
		display: flex;
		padding-top: 6px;
		padding-left: 9px;
		padding-right: 9px;
		height: 24px;
		border-radius: 4px;
		justify-content: space-between;

		.select {
			flex: 1;
		}
	}

	.botBtn {
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		/* width: 100%; */
		right: 0;
		padding: 20rpx;
		left: 0;
		bottom: 120rpx;
	}

	.custom-style {
		width: 48% !important;
	}
</style>